<template name='goods_money'>
	<view >
		<!-- 商品信息-右边 -->
		<view class="box-infos font13  " >
			<view class="content-box">
				<view class="boxsss" >
					<!-- 增加、删除 -->
					<view class="top-but menu-scroll-w"  style="height: auto;display: block;    margin:  0px;">
						<view class="top-but-box " style="display: block;">
							<!-- 时间 筛选 -->
							<!-- <text selectable="true"  class="justify">时间范围:</text> -->
							<view class="flex floatleft" >
								
								<text selectable="true"  class="riskTitle ">时间范围:</text>
								<view class=" date-center searchBox" >
									<picker class="date-left" 
									mode="date" 
									:value="sousou.date.value[0]" 
									@change="changeStartDate"
									>
										<view class="uni-input cursor">{{sousou.date.value.length >0 ? sousou.date.value[0]:'开始时间'}}</view>
									</picker>
									
									<view class="date-c"> - </view>
									
									<picker class="date-left" 
									mode="date" 
									:value="sousou.date.value[1]" 
									@change="changeEndDate"
									>
										<view class="uni-input cursor">{{sousou.date.value.length >1 ? sousou.date.value[1]:'结束时间'}}</view>
									</picker>
									
									<view class="delete-ipu" 
									style="position: unset;transform: none;"
									v-if="sousou.date.value.length >1" 
									@click="sousou.date.value=[],funOrderAllAdmin(true)"
									>
										<img src="../../static/img/delete-1.png"  ></img>
									</view>
								 </view>
							</view>
							<!-- end -->
							<!-- 线路 筛选 -->
							<view class="flex floatleft" >
							<text selectable="true"  class="riskTitle ">所属线路:</text>
							<view class="flex searchBox" >
								<view class="input_confirms" >
									<uni-data-select
									:localdata="$routeData.getRoute()"
									v-model="route.now_id"
									@change="funOrderAllAdmin(true)"
									placeholder="选择线路"
									placeholder-class="placeholder-class"
									class="color-e40318"
									></uni-data-select>
								</view>
							</view>
							</view>
							<!-- end -->
							<!-- 是否过账 筛选 -->
							<!-- <text selectable="true"  class="justify ">过账类型:</text> -->
							<view class="flex floatleft" >
								<text selectable="true"  class="riskTitle ">是否过账:</text>
								<view class="input_confirms searchBox">
									<uni-data-select
									:localdata="sousou.accomplish.list"
									v-model="sousou.accomplish.now_id"
									placeholder="是否过账"
									placeholder-class="placeholder-class"
									class="color-e40318"
									@change="funOrderAllAdmin(true)"
									></uni-data-select>
								</view>
							</view>
							<!-- end -->
							
							<!-- 是否打印 筛选 -->
							<!-- <text selectable="true"  class="justify ">是否已打印:</text> -->
							<view class="flex floatleft">
								<text selectable="true"  class="riskTitle ">是否打印:</text>
									<view class="input_confirms searchBox">
										<uni-data-select
										:localdata="isprint.list"
										v-model="isprint.now_id"
										placeholder="是否打印"
										placeholder-class="placeholder-class"
										class="color-e40318"
										@change="funOrderAllAdmin(true)"
										></uni-data-select>
									</view>
							</view>
							<!-- end -->
							
							<!-- 订单类型 筛选 -->
							<view class="flex floatleft" >
								<text selectable="true"  class="riskTitle ">订单类型:</text>
								<view class="input_confirms searchBox">
									<uni-data-select
									:localdata="orderStatus.list"
									v-model="orderStatus.now_id"
									placeholder="订单类型"
									placeholder-class="placeholder-class"
									class="color-e40318"
									@change="funOrderAllAdmin(true)"
									></uni-data-select>
								</view>
							</view>
							<!-- end -->
							
							
							<!-- 商品类型 筛选 -->
							<view class="flex floatleft" >
								<text selectable="true"  class="riskTitle ">商品类型:</text>
								<view class="input_confirms searchBox">
									<uni-data-select
									:localdata="typeTextArr"
									v-model="sousou.typeText"
									placeholder="订单类型"
									placeholder-class="placeholder-class"
									class="color-e40318"
									@change="funOrderAllAdmin(true)"
									></uni-data-select>
								</view>
							</view>
							<!-- end -->
							
							<!-- 商品类型 筛选 -->
							<view class="flex floatleft" >
								<text selectable="true"  class="riskTitle ">制单者:</text>
								<view class="input_confirms searchBox">
									<uni-data-select
									:localdata="$routeData.getYuangong()"
									v-model="sousou.YuangongId"
									placeholder="订单类型"
									placeholder-class="placeholder-class"
									class="color-e40318"
									@change="funOrderAllAdmin(true)"
									></uni-data-select>
								</view>
							</view>
							<!-- end -->
						
							<!-- 客户名称-->
							<view class="flex floatleft" >
								<view class="riskTitle">客户名称:</view>
								<!-- 搜索 -->
								<view class="searchBox" style="min-width: 100px;max-width: 150px;">
									<input 
									v-model="sousou.user_value"
									
									placeholder="输入客户关键字"
									placeholder-class="placeholder-class"
									@confirm="$common.noMultipleClicks('funOrderAllAdmin',funOrderAllAdmin,true)"
									class="search-ipu "
									/>
									<view class="delete-ipu" v-if="sousou.user_value!=''" @click="sousou.user_value='',funOrderAllAdmin(true)">
										<img src="../../static/img/delete-1.png"  ></img>
									</view>
								</view>
							</view>
							<!-- end -->
							
							<!-- 商品名称-->
							<view class="flex floatleft" >
								<view class="riskTitle">商品名称:</view>
								<!-- 搜索 -->
								<view class="searchBox" style="min-width: 100px;max-width: 150px;">
									<input 
									v-model="sousou.goods_value"
									
									placeholder="输入商品关键字"
									placeholder-class="placeholder-class"
									@confirm="$common.noMultipleClicks('funOrderAllAdmin',funOrderAllAdmin,true)"
									class="search-ipu "
									/>
									<view class="delete-ipu" v-if="sousou.goods_value!=''" @click="sousou.goods_value='',funOrderAllAdmin(true)">
										<img src="../../static/img/delete-1.png"  ></img>
									</view>
								</view>
							</view>
							<!-- end -->
							
							<!-- 订单号-->
							<view class="flex floatleft" >
								<view class="riskTitle">订单号码:</view>
								<!-- 搜索 -->
								<view class="searchBox" style="min-width: 100px;max-width: 150px;">
									<input 
									v-model="sousou.order_id"
									
									placeholder="输入搜索订单号关键字"
									placeholder-class="placeholder-class"
									@confirm="$common.noMultipleClicks('funOrderAllAdmin',funOrderAllAdmin,true)"
									class="search-ipu "
									/>
									<view class="delete-ipu" v-if="sousou.order_id!=''" @click="sousou.order_id='',funOrderAllAdmin(true)">
										<img src="../../static/img/delete-1.png"  ></img>
									</view>
								</view>
							</view>
							<!-- end -->
							
						</view>
						<view class="top-but-box ">
							
							<!-- 时间 筛选 -->
							<button 
								@click="$common.noMultipleClicks('funOrderAllAdmin',funOrderAllAdmin,true)" 
								class="nowBut color1"
							>
								<img src="../../static/img/search.png" class="ico"></img>
								刷新
							</button>
							
							<button 
								@click="emptyData()" 
								class="nowBut color2" 
							>
								<img src="../../static/img/delete.png" class="ico"></img>
								重置
							</button>
							
							<button
							@click="$my_excel.goodsOrder(resData,false)"
							class="nowBut color7 font12" 
							>
								导出
							</button>
						</view>
					</view>
					<table id="goods-money" v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th style="min-width: 20px;">
									序
								</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',0)">时间</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',2)">
									线路
								</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',9)">
									方式
								</th>
								<th @click="$common.changeColumnColor('goods-money',1)">客户</th>
								
								<th class="centers" @click="$common.changeColumnColor('goods-money',4)">
									商品类型
								</th>
								<th @click="$common.changeColumnColor('goods-money',3)">商品</th>
								
								<th class="centers" @click="$common.changeColumnColor('goods-money',4)">
									单位
								</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',5)">单价</th>
								<th class="centers" >数量</th>
								<th class="centers" >合计</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',6)">利润</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',7)">利率</th>
								<th class="centers" @click="$common.changeColumnColor('goods-money',8)">
									制单者
								</th>
								<th class="centers">操作</th>
								<th class="centers">备注</th>
							</tr>
						</thead>
						<tbody>
							
								<!-- 内容 -->
								<tr v-for="(item,index) in resData.list" 
								:key="index"  
								@click="TabcheckedIndex = index"
								:class="TabcheckedIndex == index ? 'goods-list-select':''"
								>
									<td>
										{{index+1}}
									</td>
								
									
									<td class="centers col-0" >
										<text selectable="true">
											{{item.date}}
										</text>
									</td>
									<td class="centers col-2">
										<text selectable="true">
											{{item.route_name}}
										</text>
									</td>
									<td class="weight col-9 centers"
									:class="{ff2626:item.order_status==1}"
									:title="item.order_status==0 ? $global.title.m29_1:$global.title.m29">
										<text selectable="true">
											{{item.order_status==1?'商城单':'后台单'}}
										</text>
									</td>

									<td class="weight alter col-1"
									@click="pageSend.user_id=item.user.id,pageSend.name=item.user.name,$refs.page_admin.open()"
									>
										<text selectable="true">
											{{item.name}}
										</text>
									</td>
									<td class="centers col-4">
										<text selectable="true">
											{{resData.typeText[item.type]}}
										</text>
									</td>
									
									

									<td class="alter col-3" @click="pageSend.goods_id=item.goods_id,pageSend.name=item.goods_name,$refs.pageGoods.open()"
									>
										<text selectable="true">
											{{item.goods_name}}
										</text>
									</td>
									<td class="centers ">
										<text selectable="true">
											{{item.data.units}}
										</text>
									</td>
									<td 
									class="centers weight col-5"
									:style="{color:item.originalPriceSum<=0 ? '#ff0000':'#2ab100'}"
									>
										<text selectable="true">
											￥{{item.money}}
										</text>
										
									</td>
									<td 
									class="centers weight "
									>
										<text selectable="true">
											{{item.counts}}
										</text>
									</td>
									<td 
									class="centers weight "
									>
										<text selectable="true">
											￥{{item.sum_money}}
										</text>
									</td>


									<td class="centers weight col-6" :class="parseFloat(item.profit)<=0 ?'color-e40318':''">
										<text selectable="true">
											￥{{item.profit}}
										</text>
										
									</td>
									
									
									<td class="centers weight col-7" :class="parseFloat(item.profit_ratio)<=15 ?'color-e40318':''">
										<text selectable="true">
											{{item.profit_ratio}}%
										</text>
										
									</td>
									
									<td class="centers col-8" 
									@click="pageSend.user_id=item.uid,pageSend.name=item.uid_name,$refs.page_admin.open()"
									>
										<text selectable="true">
											{{item.uid_name}}
										</text>
									</td>
									
									<td  class="centers alter" @click="$common.GetOrder(item.order_id,false,2)">
										单据详情
									</td>
									<td  class="centers ">
										<descr :account="item.data.account" :tipmsg="item.data.tipmsg" :value="item.descr" :order_id="item.id"></descr>
									</td>
								</tr>
							
						</tbody>
					</table>
					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>

				<!-- end -->
				<!-- 合计 -->
				<view class="flex bottom c565656 font12" v-if="resData.list && resData.list.length>0">
					<view class="flex">
						<view class="justify">合计: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.data!=undefined ? resData.data.sum:0}}</view>
							<view class="justify">元</view>
						</view>
					</view>
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">利润: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.data!=undefined ? resData.data.profit:0}}</view>
							<view class="justify">元</view>
						</view>
					</view>
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">利率: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.data!=undefined ? resData.data.profit_ratio:0}}</view>
							<view class="justify">%</view>
						</view>
					</view>
					
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">销售总数: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.count!=undefined ? resData.count.xiaoshou:0}}</view>
						</view>
					</view>
					
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">退回坏: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.count!=undefined ? resData.count.tuihuai:0}}</view>
						</view>
					</view>
					
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">退回好: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.count!=undefined ? resData.count.tuihao:0}}</view>
						</view>
					</view>
					
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">赠送: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.count!=undefined ? resData.count.zengsong:0}}</view>
						</view>
					</view>
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">进货: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.count!=undefined ? resData.count.jinhuo:0}}</view>
						</view>
					</view>
					<view style="height: 1px;width: 20px;"></view>
					<view class="flex">
						<view class="justify">厂家赠送: </view>
						<view class="ipu flex border1 ">
							<view class="justify money ">{{resData.count!=undefined ? resData.count.changjiazengsong:0}}</view>
						</view>
					</view>
					<view style="height: 1px;width: 20px;"></view>
					
				</view>
				
				<view class="button-tips">
					<view class="justify">计算公式:在指定的筛选条件内所有已过账的单据款合计总金额-各个商品的进货价=利润</view>
				</view>
				<!-- end -->
				
				<!-- 页码 -->
				<pages 
				:current="page.nowPage"
				:sum="page.sum"
				@updatePage="updatePage"
				></pages>
				<!-- end -->
			</view>
			<!-- 数据列表end -->


			<!-- 用户详情页 -->
			<uni-popup ref="page_admin" type="center" :title="pageSend.name" >
				<person_admin
				:OnPageSearchUserId="pageSend.user_id" 
				status="firm_user_list" 
				class="page-boxs h100"
				></person_admin>	
			</uni-popup>
			<!-- end -->
			
			<!-- 商品页面 -->
			<uni-popup ref="pageGoods" type="center" :title="pageSend.name">
				<shopping_admin :isPop="false" :OnPageSearchGoodsId="pageSend.goods_id"  class="h100"></shopping_admin>
			</uni-popup>
			<!-- end -->
		</view>
		<!-- end -->
	</view>
</template>

<script>
	import pages from "@/components/admin-components/pages.vue"
	import empty from "@/components/admin-components/empty.vue"
	import person_admin from "@/components/user/list.vue"
	import descr from "@/components/descr/descr.vue"
	import shopping_admin from "@/components/goods/goods.vue"
	export default{
		name:'goods_money',
		components: {
			pages,empty,person_admin,descr,shopping_admin
		},
		beforeCreate(){
			this.$options.components.order_money = require('@/components/admin-components/order_money.vue').default 
		},
		data(){
			return{
				typeTextArr:[],
				TabcheckedIndex:-1,//当前选中项
				PrintOrderData:{},//欲要打印的订单数据
				pageSend:{
					user_id:'',
					goods_id:'',
					name:''
				},
				sousou:{
					typeText:'0',
					date:{
						value:[]
					},
					user_value:'',
					uid_value:'',
					goods_value:'',
					order_id:'',
					YuangongId:'',
					accomplish:{
						now_id:'',
						list:[//客户的时候线路下拉选择框
							{
								text:'不限过账',
								value:'',
								disable:false,//是否禁用
							},{
								text:'未过账',
								value:'3',
								disable:false,//是否禁用
							},{
								text:'已过账',
								value:'2',
								disable:false,//是否禁用
							},
						],
					},
					
					gongyingshang:{
						now_id:'1',
						list:[//客户的时候线路下拉选择框
							{
								text:'客户',
								value:'1',
								disable:false,//是否禁用
							},{
								text:'供应商',
								value:'2',
								disable:false,//是否禁用
							}
						],
					}
				},
				page:{
					
					nowPage:1,//当前页数
					pageCount:1,//总页数
					maxCount:0,
					sum:0,
					pageCounts:15,
				},
				isprint:{
					list:[
						{
							value:'1',
							text:'不限'
						},
						{
							value:'2',
							text:'已打印'
						},
						{
							value:'3',
							text:'未打印'
						},
					],
					now_id:'1',//当前选中
				},
				
				orderStatus:{
					list:[
						{
							value:'',
							text:'不限'
						},
						{
							value:'1',
							text:'商城单'
						},
						{
							value:'2',
							text:'后台单'
						},
					],
					now_id:'',//当前选中
				},
				resData:{},
			
				route:{
					now_id:'',
				},
			}
		},
		 // 此处定义传入的数据
		props: {
			/**
			 * 其他页面传递进来直接搜寻的，不是菜单打开的
			*/
			OnPageSearchUid: {
				type:String,
				default :''
			},
			/**
			 * 时间范围 开始
			*/
			start_date: {
				type:String,
				default :''
			},
			/**
			 * 时间范围 结束
			*/
			end_date: {
				type:String,
				default :''
			},
			/**
			 * 区分供货商或客户
			*/
			supplier: {
				type:String,
				default :''
			},
		},
		mounted(){
		},
		created() {
			//判断是否有搜索内容，有的话植入，且搜索条件为：只看客户
			if(this.OnPageSearchUid != undefined && this.OnPageSearchUid != ''){
				this.sousou.uid_value = this.OnPageSearchUid
				
				this.isprint.now_id = "1"
				//console.log("//判断是否有搜索内容，有的话植入，且搜索条件为：只看客户")
			}else{
				
				//判断是有  时间条件
				if(this.start_date != undefined && this.start_date.length>0 && this.end_date != undefined && this.end_date.length>0){
					this.sousou.date.value.push(this.start_date)
					this.sousou.date.value.push(this.end_date)
				}else{
					var date = this.$common.GetFormattedDate()
					this.sousou.date.value.push(date)
					this.sousou.date.value.push(date)
				}
				
			
				this.route.now_id = this.$routeData.GetNowRoute()
				
			}
			this.funOrderAllAdmin(true)
		},
		methods:{
			//回调第一个时间
			changeStartDate(res){
				this.sousou.date.value[0] = res.detail.value
				this.$set(this.sousou.date.value,0,this.sousou.date.value[0])
				//this.funOrderAllAdmin(true)
			},
			//回调第二个时间
			changeEndDate(res){
				this.sousou.date.value[1] = res.detail.value
				this.$set(this.sousou.date.value,1,this.sousou.date.value[1])
			},
			/**
			 * 初始化筛选条件
			*/
			emptyData(){
				this.sousou.user_value=''
				this.sousou.uid_value =''
				this.sousou.date.value =[]
				
				this.sousou.accomplish.now_id=''
				this.isprint.now_id ='1'
				this.route.now_id = ''
				//this.choos_all_close()
			},
			/**
			 * 线路ID取线路名称
			*/
			routeidGetName(id){
				var tmpArr = this.$routeData.getRoute()
				
				for (var i=0;i<tmpArr.length;i++) {
					if(tmpArr[i].value == id){
						return tmpArr[i].text
					}
				}
				return '-'
			},
			/**
			 * 统计-获取
			*/
			funOrderAllAdmin(isUpdatePage=true){
				var that = this
				//日期构建
				if(that.sousou.date.value.length>=2){
					var start_date = that.sousou.date.value[0]
					var end_date = that.sousou.date.value[1]
				}else{
					var start_date = ''
					var end_date = ''
				}
				that.resData = {}
				that.page.nowPage = isUpdatePage == true ? 1:that.page.nowPage;
				that.$common.get_request(
					{
						type:'order_all_goods',
						pages:that.page.nowPage,
						page_count:that.page.pageCounts,//当前请求页的数量
						start_date: start_date,
						end_date: end_date,
						isprint: that.isprint.now_id,
						goods_value: that.sousou.goods_value,
						user_value: that.sousou.user_value,
						order_id:that.sousou.order_id,
						uid: that.sousou.uid_value,
						route_id:that.route.now_id,
						accomplish:that.sousou.accomplish.now_id,
						supplier:that.sousou.gongyingshang.now_id,//区分上一个页面传递过来的是客户还是厂家
						status:0,//0=不获取回款记录
						show_goods_list:0,
						yg_id:this.sousou.YuangongId,
						typeText:that.sousou.typeText,
						orderStatus:this.orderStatus.now_id
					},
					(res)=>{
						for (var i=0;i<res.list.length;i++) {
							res.list[i].route_name = that.routeidGetName(res.list[i].route_id)
						}
						that.resData = res
						
						that.page.sum  = res.sum
						if(isUpdatePage == true){
						that.page.nowPage  = 1
						}
						
						
						if(that.typeTextArr.length<=0){
							for (var i=0;i<res.typeText.length;i++) {
								if(res.typeText[i].length>0){
									that.typeTextArr.push({text:res.typeText[i],value:i})
								}
								
							}
						}
						
						
						//that.choos_all_close()
					}
				);
			},
			/**
			 * 分页器回调
			 * 
			*/
			updatePage(pageName,pageCount){
				var that = this
				that.page.nowPage = pageName
				that.page.pageCounts = pageCount
				that.funOrderAllAdmin(false)
			},
		}
	}
</script>

<style>
	.button-tips{
		margin-right: auto;
		margin-left: 5px;
		color: #565656
	}
	.top-but-box .floatleft{
		margin: 5px 10px 5px 0px;
	}
</style>
